$(function() {
	//检查登录页是不是在顶级窗口,如果不是,那么使用顶级窗口重新加载登录页
	if(top!=window) {
		top.location.href=contextPath+'/user/admin/login';
		return;
	}
	$('input[name=username]').focus();
	$('input[name=password]').keydown(function(event) {
    	if(event.keyCode==13) {
    		login();
    	}
    });
});

function login() {
	$('#system-msg').text('');
	//if(!$('#login-form').form('validate')) return;
	var name = $('#name').val();
	var password = $('#password').val();
	var verifyCode = $('#verifyCode').val();
	if (verifyCode == null || verifyCode == '') {
		alert('请输入验证码');
		return;
	}
	var params = {"name":name,"password":password,"verifyCode":verifyCode};
	$.post(contextPath+'/user/admin/login',params,function(result) {
		if(result.code==1) {
			window.location.href=contextPath+result.msg;
		} else {
			$('#system-msg').text(result.msg).show();
		}
	},'json');
}

function getVerifycode() {
	var imgVerifyCode = document.getElementById("imgVerifyCode");
	imgVerifyCode.src = contextPath+'/user/admin/verify?t='+new Date();
}

